function hash(password)
{
    var secure = '~!@#$%^&*()_+[]';
    return md5(sha1(password)+secure);
}

function loginController($scope)
{
    $scope.applogin = function()
    {
        $scope.app_login_hash = hash($scope.app_login_password);
    };
}

// not at this time
function registerController($scope)
{
    var checkFullName;
    var checkEmail;
    var checkPassword;

    $('#app_register_fullname').keyup(function(e) {
        var fullName = $scope.app_input_fullname;
        if (fullName.length < 2) {
            //console.log("Full name must be at least 2 characters");
        }
        else {
            /**
             * boolean: pattern
             * @type {boolean}
             */
            var pattern = /^[a-zA-z ]+$/.test(fullName);
            checkFullName = pattern;
        }
    });

    $('#app_register_confirm_password').keyup(function (e) {
        if ($scope.app_register_password != $scope.app_register_confirm_password) {
            //tips_normal('#app_register_confirm_password input', app.alert.app_register_confirm_password, true);
            checkPassword = false;
        }
        else
        {
            checkPassword = true;
        }
    });

    $('#app_register_email').keyup(function(e) {
        /*
        func.send('checkEmail', {email: $scope.app_input_email}, function(result){
           console.log(result);
        });
        */

        var userName = $scope.app_input_email;
        if (userName.length < 5) {
            console.log("Length of User name must be at least 5 charaters!");
        } else {
            /**
             * boolean: ok
             * [a-zA-Z0-9@._]
             * @type {boolean}
             */
            var ok = /^([\w@.]{5,30})$/.test(userName);
            checkEmail = ok;
        }
    });

    $scope.appsignup = function()
    {
        $scope.app_register_hash = hash($scope.app_register_password);

        if (checkFullName == true &&
            checkEmail == true &&
            checkPassword == true)
        {
            document.registerForm.submit();
        }
    };
}

// NOT AT THIS TIME
function confirmController($scope)
{
    $('#app_confirm_question').keyup(function(e) {
        var question = $scope.app_confirm_question;
        var pattern = /[a-zA-Z ]+/.test(question);

        if (pattern == true)
            console.log('OK');
        else
            console.log('Wrong');
    });

    $scope.button_continue_register = function()
    {
        document.confirmForm.submit();
    }
}

function tips_normal (selector, text, show) {
    var options = function(text) {
        return {
            animation:'true',
            deplay:1000,
            placement : 'left',
            content:text,
            container:'body'
        }
    }

    $(selector).popover(options(text));
    if (typeof show!=undefined)
    {
        $(selector).popover('show');
    }
}

$(document).ready(function() {

    //tips_normal('#app_register_password input', app.alert.register_password_notice);

    $('#app_register_password input').focusout(function() {
        $(this).popover('hide');
    });

    $('.app_register_question_suggest li').click(function() {
        var text = $(this).find('a')[0].innerHTML;
        $('#app_register_question').val(text);
    });

    //$('.combobox').combobox();
});